#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

int gcd(int x, int y)
{
    return y == 0 ? x : gcd(y, x % y);
}

int countBeautifulPairs(int* nums, int numsSize)
{
    int ret = 0;
    int i = 0;
    int j = 0;
    for (i = 0; i < numsSize - 1; i++)
    {
        while (nums[i] >= 10)
        {
            nums[i] /= 10;
        }
        for (j = i + 1; j < numsSize; j++)
        {
            if (gcd(nums[i], nums[j] % 10) == 1)
            {
                ret++;
            }
        }
    }
    return ret;
}